/**
 * Created with IntelliJ IDEA.
 * Description: leetcode.面试题.简单题.17.04.消失的数字
 */

//方法一：通过异或表达式
class Solution1 {
    public int missingNumber(int[] nums) {
        int temp = 0;
        for(int i = 0; i < nums.length; i++) {
            temp ^= nums[i];
            temp ^= i;
        }
        temp ^= nums.length;
        return temp;
    }
}

//方法二：通过求和相减
class Solution2 {
    public int missingNumber(int[] nums) {
        int sum = 0;
        for(int i = 0; i < nums.length; i++) {
            sum += nums[i];
        }
        return (nums.length) * (1 + nums.length) / 2 - sum;
    }
}

public class Test {
}
